package com.itxiuyixiu.security.controller;

import com.itxiuyixiu.entity.model.Admin;
import com.itxiuyixiu.entity.model.User;
import com.itxiuyixiu.security.mapper.AdminMapper;
import com.itxiuyixiu.security.mapper.UserMapper;
import com.itxiuyixiu.tools.util.returns.ReturnVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 黄磊
 * @date 2020/5/1
 */
@Profile("dev")
@RestController
public class TestController {
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Resource
    private AdminMapper adminMapper;
    @Resource
    private UserMapper userMapper;

    @GetMapping("/test")
    public ReturnVo aaa() {
        return ReturnVo.getSuccessReturn("aaaaaaaa");
    }

    @PostMapping("/test/admin")
    public ReturnVo registerAdmin(Admin admin) {
        admin.setPassword(passwordEncoder.encode(admin.getPassword()));
        adminMapper.insertAdmin(admin);
        return ReturnVo.getSuccessReturn("成功上传");
    }

    @PostMapping("/test/user")
    public ReturnVo registerUser(User user) {
        user.setPassword(passwordEncoder.encode(user.getPassword()));
        userMapper.insertUser(user);
        return ReturnVo.getSuccessReturn("成功上传");
    }
}
